use actix_web::{get, Responder};
use actix_web::web::Json;
use serde::{Serialize, Deserialize};
use crate::extends::core::errors::response_code_enums::ResponseCodeEnum;
use crate::extends::core::initialize::banner_tools::BannerTool;
use crate::extends::core::response::reponse_data::*;


#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IndexParam {
    contents: Option<String>,
}

#[get("/admin/index/index")]
pub async fn index(Json(vo): Json<IndexParam>) -> impl Responder {
    log::info!("{:?} ", vo);
    return R::success(Some("Hello word!"));
}


#[get("/admin/index/banner")]
pub async fn banner() -> impl Responder {
    let project_name = "xinhou-actix-admin";
    let banner = BannerTool::generate_banner(project_name);
    match BannerTool::write_banner_to_file(&banner, "banner.txt") {
        Ok(_) => R::success(Some("Banner generated success!")),
        Err(err) => {
            log::error!("Failed to generated banner: {}", err);
            R::error(ResponseCodeEnum::INTERNAL_SERVER_ERROR)
        }
    }
}

